import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/guider_associate";

export const index_api = (showError = true) => {
  return Http.get<{
    banner: any[];
    introduce: { title: string; introduce: string };
    associate_news: any[];
  }>(`/v3${baseUrl}/index`).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const get_area_api = (showError = true) => {
  return Http.get<{ items: any[] }>(`/v3${baseUrl}/get_area`).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const list_api = (
  data: { area_id: string; is_settle: number } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(`/v3${baseUrl}/list`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const info_api = (data: { id: string }, showError = true) => {
  return Http.get<any>(`/v3${baseUrl}/info`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const news_api = (
  data: { associate_id: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(`/v3${baseUrl}/news`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const news_info_api = (data: { id: string }, showError = true) => {
  return Http.get<any>(`/v3${baseUrl}/news_info`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
